Skip to content

boot: bootutil: Do not panic on unreadable primary slot trailer - #2805

Open
fbnors wants to merge 1 commit into
mcu-tools:mainfrom
fbnors:fix-unreadable-primary-trailer-overwrite-only
Open

boot: bootutil: Do not panic on unreadable primary slot trailer#2805
fbnors wants to merge 1 commit into
mcu-tools:mainfrom
fbnors:fix-unreadable-primary-trailer-overwrite-only

Conversation

@fbnors

@fbnors fbnors commented Jul 27, 2026

Copy link
Copy Markdown

boot_swap_type_multi() returns BOOT_SWAP_TYPE_PANIC whenever the swap state of the primary slot cannot be read. On devices whose flash controller reports a read error for pages that have never been programmed, this happens as soon as part of the primary trailer is still erased, which permanently blocks both booting and firmware recovery.

In overwrite-only mode the bootloader never resumes an interrupted swap from the primary trailer and never sets its copy_done flag, so no entry of boot_swap_tables can match on the primary state. An unreachable primary trailer is therefore treated as empty there, the same way an unreachable secondary slot already is. The swap based modes keep returning BOOT_SWAP_TYPE_PANIC, because they do need the primary trailer to resume a swap safely.

boot_swap_type_multi() returns BOOT_SWAP_TYPE_PANIC whenever the swap
state of the primary slot cannot be read. On devices whose flash
controller reports a read error for pages that have never been
programmed, this happens as soon as part of the primary trailer is
still erased, which permanently blocks both booting and firmware
recovery.

In overwrite-only mode the bootloader never resumes an interrupted
swap from the primary trailer and never sets its copy_done flag, so
no entry of boot_swap_tables can match on the primary state. An
unreachable primary trailer is therefore treated as empty there, the
same way an unreachable secondary slot already is. The swap based
modes keep returning BOOT_SWAP_TYPE_PANIC, because they do need the
primary trailer to resume a swap safely.

Signed-off-by: Fabian Otto <fabian.otto@rohde-schwarz.com>
@fbnors
fbnors requested a review from davidvincze as a code owner July 27, 2026 09:23
@nordicjm

Copy link
Copy Markdown
Collaborator

boot_swap_type_multi() returns BOOT_SWAP_TYPE_PANIC whenever the swap state of the primary slot cannot be read.

As it should

On devices whose flash controller reports a read error for pages that have never been programmed, this happens as soon as part of the primary trailer is still erased, which permanently blocks both booting and firmware recovery.

Sounds like a problem with the flash controller then, this isn't a problem of MCUboot

@fbnors

fbnors commented Jul 28, 2026

Copy link
Copy Markdown
Author

As it should

The change only affects the OVERWRITE_ONLY mode. In that mode, MCUboot does not resume an interrupted update from the primary trailer. Treating an unreadable primary trailer as empty is equivalent to how an unreadable secondary slot is already handled today.

Sounds like a problem with the flash controller then

In my case, the issue happened with the NXP LPC55 flash. The Zephyr driver already maps fully erased pages to 0xFF (see zephyr#24429). But it can still return BOOT_EFLASH if the trailer page is partially written or otherwise unreadable, e.g. because of a real ECC error.

this isn't a problem of MCUboot

Returning BOOT_SWAP_TYPE_PANIC aborts inside boot_go before CONFIG_BOOT_SERIAL_NO_APPLICATION can enter serial/USB recovery. So a recoverable empty/corrupt primary flash page effectively bricks the device. Treating the primary as empty at least allows recovery.

@nordicjm
nordicjm requested a review from d3zd3z July 31, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants